import { FETCH_LEVELS_REQUEST, FETCH_LEVELS_SUCCESS, FETCH_LEVELS_FAILURE, LevelState, LevelsActionTypes } from '../types/levelsTypes'

const initialState: LevelState = {
  isFetching: false
}

export default (state = initialState, action: LevelsActionTypes) => {
  switch (action.type) {
    case FETCH_LEVELS_REQUEST:
      return { isFetching: true }
    case FETCH_LEVELS_SUCCESS:
      return {
        isFetching: false,
        levels: action.levels
      }
    case FETCH_LEVELS_FAILURE:
      return {
        isFetching: false,
        error: action.error
      }
    default:
      return state;
  }
}
